﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using WL_Store.Model;
using WL_Store.BLL;
using System.Net;
using System.Web.Services;

namespace WL_Store.Web.subpage
    
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void login_btn_Click(object sender, EventArgs e)
        {
            ////获取用户名、密码和验证码
            //string name = this.username.Text.Trim();
            //string password = this.userpwd.Text;
            //string code = this.Codes_text.Text;
            ////获取session中code储存的随机验证码的值
            //string code1 = Session["Code"].ToString();
            ////判断用户输入的验证码是否和产生的验证码一致
            //if (code.ToUpper() != code1.ToUpper())
            //{
            //    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert(' 验证码错误！！！ '); </script> ");
            //}
            //else
            //{
            //    EmployeeInfoBLL bll = new EmployeeInfoBLL();
            //    //LoginBLL lb = new LoginBLL();
            //    EmployeeInfoModel Log = bll.EmployeeInfo(name, password);

            //    if (Log != null)
            //    {
            //        AddLoginLogs();
            //        Session["EmployeeInfo"] = Log;
            //        Response.Redirect("Index.aspx");
            //    }
            //    else
            //    {
            //        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert(' 用户名或密码错误！！！ '); </script> ");
            //    }



            //}
            #region ADO.NET

            //创建连接
            //string conStr = "Data Source=.;Initial Catalog=master;Integrated Security=true;";
            //using (SqlConnection con=new SqlConnection(conStr))
            //{
            //    string sql = "select count(*) from EmployeeLogin where number=@number and password=@password";

            //    SqlParameter[] pams = { 
            //    new SqlParameter("@number",name),
            //     new SqlParameter("@password",password),
            //    };
            //    using (SqlCommand com=new SqlCommand(sql,con))
            //    {
            //        com.Parameters.AddRange(pams);
            //        con.Open();
            //        object result = com.ExecuteScalar();
            //        if (Convert.ToInt32(result)>0)
            //        {
            //            Response.Redirect("../Index.aspx");
            //        }
            //        else
            //        {
            //            Response.Write("<script language='javascript'>alert('用户名或密码错误！');</script>");
            //        }
            //    }

            //}
            #endregion

        }

        /// <summary>
        /// 添加登录日志
        /// </summary>
        //private void AddLoginLogs()
        //{
        //    LoginLogsBLL bll = new LoginLogsBLL();
        //    //获取页面登录名
        //    string LoginName = this.username.Text.Trim();
        //    //获取用户姓名
        //    string AdminName = bll.GetName(LoginName).ToString();
        //    //获取当前计算机名
        //    string ServerName = Dns.GetHostName();
        //    //获取本地的IP地址
        //    string AddressIP = string.Empty;
        //    foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
        //    {
        //        if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
        //        {
        //            AddressIP = _IPAddress.ToString();
        //        }
        //    }
        //    //获取当前时间
        //    DateTime dateTime = DateTime.Now;

        //    LoginLogsModel model = new LoginLogsModel()
        //    {
        //        LoginName = LoginName,
        //        AdminName = AdminName,
        //        ServerName = ServerName,
        //        ClientIP = AddressIP,
        //        LoginTime = dateTime
        //    };
        //    bll.AddLonginLog(model);

        //}



        //[WebMethod]
        //private static void LoginClick(string name,string password)
        //{
        //    name = HttpContext.Current.Request.Form["name"];
        //    password = HttpContext.Current.Request.Form["password"];

        //    EmployeeInfoBLL bll = new EmployeeInfoBLL();
        //    //LoginBLL lb = new LoginBLL();
        //    EmployeeInfoModel Log = bll.EmployeeInfo(name, password);
        //    if (Log != null)
        //    {
        //        //AddLoginLogs();
        //        HttpContext.Current.Session["EmployeeInfo"] = Log;
        //        HttpContext.Current.Response.Write("ok");
        //    }
        //    else
        //    {
        //        HttpContext.Current.Response.Write("用户名或密码错误！");
        //    }
        //}

    }
}